from django.shortcuts import render
from django.views.generic import ListView,DetailView
from .models import PersonInfo
from django.http import HttpResponse
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView
from django.views.generic.dates import MonthArchiveView, WeekArchiveView
from .forms import PersonForm

def home(request):
    return HttpResponse("Welcome to the homepage!")

class PersonListView(ListView):
    model = PersonInfo
    template_name = 'person_list.html'
    context_object_name ='person_list'

class PersonDetailView(DetailView):
    model = PersonInfo
    template_name = 'person detail.html'
    context_object_name = 'person'

class PersonFormView(FormView):
    template_name = 'person_form.html'
    form_class = PersonForm
    success_url = '/myapp/persons/'
    
    def form_valid(self, form):
        form.save()
        return super().form_valid(form)

class PersonCreateView(CreateView):
    model = PersonInfo
    form_class = PersonForm
    template_name = 'Person_form.html'
    success_url = '/myapp/persons/'

class PersonUpdateView(UpdateView):
    model = PersonInfo
    form_class = PersonForm
    template_name = 'Person_form.html'
    success_url = '/myapp/persons/'

class PersonDeleteView(DeleteView):
    model = PersonInfo
    template_name = 'person_confirm_delete.html'
    success_url = '/myapp/persons/'

class PersonMonthArchiveView(MonthArchiveView):
    queryset = PersonInfo.objects.all()
    date_field = 'hireDate'
    template_name = 'person_month_archive.html'
    month_format = '%m'

class PersonWeekArchiveView(WeekArchiveView):
    queryset = PersonInfo.objects.all()
    date_field = 'hireDate'
    template_name = 'person_week_archive.html'
    week_format = '%W'